package ThreadPool.jike.demo16;

import java.util.concurrent.Semaphore;

/**
 * @param
 * @author oyz
 * @version 1.1.0
 * @description: 信号量
 * @date 2022-8-25 17:23
 */
public class SemaphoreTest {

    static int count = 1;
    // 非公平锁信号量
    static final Semaphore lock = new Semaphore(1);


    public void addOne() throws InterruptedException {
        // 进来首先会判断是否是大于0.是的话(小于0会进入等待)会进入等待
        lock.acquire();
        try{
            count += 1;
        }finally {
            // 放行(当前值小于等于0),当前值加一
            lock.release();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        new SemaphoreTest().addOne();
    }
}
